// 视力结果分析工具库
/**
 * 从角膜曲率数据格式中提取度数数值
 * @param {string} input - 输入字符串，格式如 "7.88/42.75D@175°"
 * @returns {string|null} - 提取的度数数值（如 "42.75"），若格式不匹配则返回 null
 */
function extractDiopterValue(input) {
    if (typeof input !== "string") return null;

    // 使用正则表达式匹配中间的度数部分
    const regex = /\/(\d+(?:\.\d+)?)/;
    const match = input.match(regex);

    return match ? match[1] : null;
}

export const visionUtils = {

    /**
     * 分析视力检查结果
     * @param {Object} resultMap - 检查结果映射
     * @param {number} age - 年龄
     * @returns {Array} [视力状态, 建议信息]
     */
    VisionResult(resultMap, age) {
        let SELeft, SERight;

        // 检查必要数据是否存在
        if (
            resultMap["left_s_avg"] === "" ||
            resultMap["right_s_avg"] === "" ||
            resultMap["left_a_avg"] === "" ||
            resultMap["right_a_avg"] === "" ||
            resultMap["ucvaLeft"] === "" ||
            resultMap["ucvaRight"] === ""
        ) {
            return this.VisionResultInfo(age, -1);
        }

        // 解析球镜数据
        const left_s_avg = parseFloat(resultMap["left_s_avg"]);
        if (left_s_avg && isNaN(left_s_avg)) {
            console.error("left_s_avg解析失败", resultMap["left_s_avg"]);
            return this.VisionResultInfo(age, -1);
        }

        // 解析柱镜数据
        const left_c_avg = parseFloat(resultMap["left_c_avg"]);
        if (left_c_avg && isNaN(left_c_avg)) {
            console.error("left_c_avg解析失败", resultMap["left_c_avg"]);
            return this.VisionResultInfo(age, -1);
        }

        const right_s_avg = parseFloat(resultMap["right_s_avg"]);
        if (right_s_avg && isNaN(right_s_avg)) {
            console.error("right_s_avg解析失败", resultMap["right_s_avg"]);
            return this.VisionResultInfo(age, -1);
        }

        const right_a_avg = parseFloat(resultMap["right_a_avg"]);
        if (right_a_avg && isNaN(right_a_avg)) {
            console.error("right_a_avg解析失败", resultMap["right_a_avg"]);
            return this.VisionResultInfo(age, -1);
        }

        const right_c_avg = parseFloat(resultMap["right_c_avg"]);
        if (right_c_avg && isNaN(right_c_avg)) {
            console.error("right_c_avg解析失败", resultMap["right_c_avg"]);
            return this.VisionResultInfo(age, -1);
        }

        const ucvaLeft = parseFloat(resultMap["ucvaLeft"]);
        if (ucvaLeft && isNaN(ucvaLeft)) {
            console.error("ucvaLeft解析失败", resultMap["ucvaLeft"]);
            return this.VisionResultInfo(age, -1);
        }

        const ucvaRight = parseFloat(resultMap["ucvaRight"]);
        if (ucvaRight && isNaN(ucvaRight)) {
            console.error("ucvaRight解析失败", resultMap["ucvaRight"]);
            return this.VisionResultInfo(age, -1);
        }

        // 计算球镜等效值
        SELeft = left_s_avg + 0.5 * left_c_avg;
        SERight = right_s_avg + 0.5 * right_c_avg;

        // 计算视力差
        const ucvaDiff = ucvaRight - ucvaLeft;

        // 根据年龄判断视力状态
        if (age === 3) {
            if ((ucvaLeft < 4.7 && (SELeft >= 2 || SELeft < 0) || left_c_avg > 1.5 || ucvaDiff > 1.5) ||
                (ucvaRight < 4.7 && (SERight >= 2 || SERight < 0 || right_c_avg > 1.5 || ucvaDiff > 1.5))) {
                return this.VisionResultInfo(age, 3);
            }
            if ((ucvaLeft < 4.7 && SELeft >= 0 && SELeft < 2 && left_c_avg <= 1.5) ||
                (ucvaRight < 4.7 && SERight >= 0 && SERight < 2 && right_c_avg <= 1.5)) {
                return this.VisionResultInfo(age, 2);
            }
            if ((ucvaLeft >= 4.7 && SELeft === 0) && (ucvaRight >= 4.7 && SERight === 0)) {
                return this.VisionResultInfo(age, 1);
            }
        } else if (age === 4 || age === 5) {
            if ((ucvaLeft < 4.8 && (SELeft >= 2 || SELeft < 0) || left_c_avg > 1.5 || ucvaDiff > 1.5) ||
                (ucvaRight < 4.8 && (SERight >= 2 || SERight < 0 || right_c_avg > 1.5 || ucvaDiff > 1.5))) {
                return this.VisionResultInfo(age, 3);
            }
            if ((ucvaLeft < 4.8 && SELeft >= 0 && SELeft < 2 && left_c_avg <= 1.5) ||
                (ucvaRight < 4.8 && SERight >= 0 && SERight < 2 && right_c_avg <= 1.5)) {
                return this.VisionResultInfo(age, 2);
            }
            if ((ucvaLeft >= 4.8 && SELeft === 0) && (ucvaRight >= 4.8 && SERight === 0)) {
                return this.VisionResultInfo(age, 1);
            }
        } else if (age === 6) {
            if ((ucvaLeft < 4.9 && (SELeft >= 2 || SELeft < 0) || left_c_avg > 1.5 || ucvaDiff > 1.5) ||
                (ucvaRight < 4.9 && (SERight >= 2 || SERight < 0 || right_c_avg > 1.5 || ucvaDiff > 1.5))) {
                return this.VisionResultInfo(age, 3);
            }
            if ((ucvaLeft < 4.9 && SELeft >= 0 && SELeft < 2 && left_c_avg <= 1.5) &&
                (ucvaRight < 4.9 && SERight >= 0 && SERight < 2 && right_c_avg <= 1.5)) {
                return this.VisionResultInfo(age, 2);
            }
            if ((ucvaLeft >= 4.9 && SELeft === 0) && (ucvaRight >= 4.9 && SERight === 0)) {
                return this.VisionResultInfo(age, 1);
            }
        } else if (age >= 7 && age <= 12) {
            if ((ucvaLeft < 4.9 && (SELeft >= 3 || SELeft < -0.5) || left_c_avg > 1.5 || ucvaDiff > 1.5) ||
                (ucvaRight < 4.9 && (SERight >= 3 || SERight < -0.5 || right_c_avg > 1.5 || ucvaDiff > 1.5))) {
                return this.VisionResultInfo(age, 3);
            }
            if ((ucvaLeft < 4.9 && SELeft >= -0.5 && SELeft < 3 && left_c_avg <= 1.5) &&
                (ucvaRight < 4.9 && SERight >= -0.5 && SERight < 3 && right_c_avg <= 1.5)) {
                return this.VisionResultInfo(age, 2);
            }
            if ((ucvaLeft >= 4.9 && SELeft > -0.5 && SELeft < 0.5) &&
                (ucvaRight >= 4.9 && SERight < 0.5 && SERight > -0.5)) {
                return this.VisionResultInfo(age, 1);
            }
        } else if (age >= 13) {
            if ((ucvaLeft < 5 && (SELeft >= 3 || SELeft < -0.5) || left_c_avg > 1.5 || ucvaDiff > 1.5) ||
                (ucvaRight < 5 && (SERight >= 3 || SERight < -0.5 || right_c_avg > 1.5 || ucvaDiff > 1.5))) {
                return this.VisionResultInfo(age, 3);
            }
            if ((ucvaLeft < 5 && SELeft >= -0.5 && SELeft < 3 && left_c_avg <= 1.5) &&
                (ucvaRight < 5 && SERight >= -0.5 && SERight < 3 && right_a_avg <= 1.5)) {
                return this.VisionResultInfo(age, 2);
            }
            if ((ucvaLeft >= 5 && SELeft > -0.5 && SELeft < 0.5) &&
                (ucvaRight >= 5 && SERight > -0.5 && SERight < -0.5)) {
                return this.VisionResultInfo(age, 1);
            }
        } else {
            return this.VisionResultInfo(age, -1);
        }

        return this.VisionResultInfo(age, -1);
    },

    /**
     * 获取视力结果信息和建议
     * @param {number} age - 年龄
     * @param {number} num - 状态码
     * @returns {Array} [视力状态, 建议信息]
     */
    VisionResultInfo(age, num) {
        let lastInfo = "";
        if (age <= 12 && age >= 7) {
            lastInfo = "";
        }
        if (age >= 13 && age <= 15) {
            lastInfo = "";
        }
        if (age >= 16 && age <= 18) {
            lastInfo = "";
        }

        switch (num) {
            case -2:
                return ["",
                    // "多吃富含维生素A、C及E的食物，如胡萝卜、菠菜等\n" +
                    // "读写连续用眼时间不宜超过40分钟，每40分钟左右要休息10分钟，可远眺或做眼保健操等\n" +
                    // "养成健康意识和用眼习惯，采纳健康行为，日间户外活动每天至少2小时\n" +
                    // "保证睡眠时间" + lastInfo
                ];
            case -1:
                return ["",
                    // "多吃富含维生素A、C及E的食物，如胡萝卜、菠菜等\n" +
                    // "读写连续用眼时间不宜超过40分钟，每40分钟左右要休息10分钟，可远眺或做眼保健操等\n" +
                    // "养成健康意识和用眼习惯，采纳健康行为，日间户外活动每天至少2小时\n" +
                    // "保证睡眠时间" + lastInfo
                ];
            case 1:
                return ['',
                    // "视力正常",
                    // "多吃富含维生素A、C及E的食物，如胡萝卜、菠菜等\n" +
                    // "读写连续用眼时间不宜超过40分钟，每40分钟左右要休息10分钟，可远眺或做眼保健操等\n" +
                    // "养成健康意识和用眼习惯，采纳健康行为，日间户外活动每天至少2小时\n" +
                    // "保证睡眠时间" + lastInfo
                ];
            case 2:
                return ["裸眼视力下降",
                    // "到医疗机构接受散瞳验光检查，明确诊断并及时采取措施\n" +
                    // "多吃富含维生素A、C及E的食物，如胡萝卜、菠菜等\n" +
                    // "读写连续用眼时间不宜超过40分钟，每40分钟左右要休息10分钟，可远眺或做眼保健操等\n" +
                    // "养成健康意识和用眼习惯，采纳健康行为，日间户外活动每天至少2小时\n" +
                    // "保证睡眠时间" + lastInfo
                ];
            case 3:
                return ["裸眼视力下降,屈光不正",
                    // "到医疗机构明确诊断并及时矫治\n" +
                    // "多吃富含维生素A、C及E的食物，如胡萝卜、菠菜等\n" +
                    // "读写连续用眼时间不宜超过40分钟，每40分钟左右要休息10分钟，可远眺或做眼保健操等\n" +
                    // "养成健康意识和用眼习惯，采纳健康行为，日间户外活动每天至少2小时\n" +
                    // "保证睡眠时间" + lastInfo
                ];
            default:
                return ["",
                    // "多吃富含维生素A、C及E的食物，如胡萝卜、菠菜等\n" +
                    // "读写连续用眼时间不宜超过40分钟，每40分钟左右要休息10分钟，可远眺或做眼保健操等\n" +
                    // "养成健康意识和用眼习惯，采纳健康行为，日间户外活动每天至少2小时\n" +
                    // "保证睡眠时间，" + lastInfo
                ];
        }
    },

    /**
     * 分析眼压检查结果
     * @param {Object} resultMap - 检查结果映射
     * @param {number} age - 年龄
     * @returns {Array} [结果, 建议, 箭头符号]
     */
    IntraocularPressure(resultMap, age) {
        if (!resultMap) {
            return ["", "", ""];
        }

        if (resultMap["leftIOPAvg"] === "" || resultMap["rightIOPAvg"] === "") {
            return this.IntraocularPressureInfo(-2);
        }

        const leftIOPAvg = parseFloat(resultMap["leftIOPAvg"]);
        if (leftIOPAvg && isNaN(leftIOPAvg)) {
            return this.IntraocularPressureInfo(-1);
        }

        const rightIOPAvg = parseFloat(resultMap["rightIOPAvg"]);
        if (rightIOPAvg && isNaN(rightIOPAvg)) {
            return this.IntraocularPressureInfo(-1);
        }

        if (leftIOPAvg > 21 || rightIOPAvg > 21) {
            return this.IntraocularPressureInfo(3);
        }

        if (leftIOPAvg < 8 || rightIOPAvg < 8) {
            return this.IntraocularPressureInfo(2);
        }

        return this.IntraocularPressureInfo(1);
    },

    // 左眼眼压分析
    LIntraocularPressure(resultMap, age) {
        if (!resultMap) {
            return ["", "", ""];
        }

        if (resultMap["leftIOPAvg"] === "") {
            return this.IntraocularPressureInfo(-2);
        }

        const leftIOPAvg = parseFloat(resultMap["leftIOPAvg"]);
        if (isNaN(leftIOPAvg)) {
            return this.IntraocularPressureInfo(-1);
        }

        if (leftIOPAvg > 21) {
            return this.IntraocularPressureInfo(3);
        }

        if (leftIOPAvg < 8) {
            return this.IntraocularPressureInfo(2);
        }

        return this.IntraocularPressureInfo(1);
    },

    // 右眼眼压分析
    RIntraocularPressure(resultMap, age) {
        if (!resultMap) {
            return ["", "", ""];
        }

        if (resultMap["rightIOPAvg"] === "") {
            return this.IntraocularPressureInfo(-2);
        }

        const rightIOPAvg = parseFloat(resultMap["rightIOPAvg"]);
        if (isNaN(rightIOPAvg)) {
            return this.IntraocularPressureInfo(-1);
        }

        if (rightIOPAvg > 21) {
            return this.IntraocularPressureInfo(3);
        }

        if (rightIOPAvg < 8) {
            return this.IntraocularPressureInfo(2);
        }

        return this.IntraocularPressureInfo(1);
    },

    /**
     * 获取眼压结果信息
     * @param {number} num - 状态码
     * @returns {Array} [结果, 建议, 箭头符号]
     */
    IntraocularPressureInfo(num) {
        switch (num) {
            case -2:
                return ["", "", ""];
            case -1:
                return ["", "", ""];
            case 1:
                return [
                    // "眼压正常",
                    "", ""];
            case 2:
                return ["眼压过低", "", ""];
            case 3:
                return ["眼压过高",
                    "患者患青光眼的风险高，需要结合其他眼内检查（角膜厚度测量、视野及眼底检查等）进行诊断", ""
                ];
            default:
                return ["", "", ""];
        }
    },

    /**
     * 生物测量数据分析
     * @param {Object} resultMap - 检查结果映射
     * @param {number} age - 年龄
     * @param {number} sex - 性别
     * @returns {Array} [结果映射, 箭头映射]
     */
    BiometricMeasurement(resultMap, age, sex) {

        const respMap = {};
        const arrowMap = {};

        if (!resultMap) {
            return [respMap, arrowMap];
        }

        // 处理左眼屈光数据1
        if (resultMap["AxialRatioLeft1"]) {
            const parts = resultMap["AxialRatioLeft1"].split("D");
            const subParts = parts[0].split("/");
            resultMap["AxialRatioLeft1"] = subParts[1];
            const left_r1_mm = parseFloat(resultMap["AxialRatioLeft1"]);
            if (!isNaN(left_r1_mm)) {
                if (left_r1_mm >= 41 && left_r1_mm <= 43) {
                    respMap["AxialRatioLeft1"] = "平坦屈光正常";
                }
                if (left_r1_mm > 43) {
                    respMap["AxialRatioLeft1"] = "平坦屈光较大，有曲率性近视风险";
                    arrowMap["AxialRatioLeft1"] = "";
                }
                if (left_r1_mm > 39 && left_r1_mm < 41) {
                    respMap["AxialRatioLeft1"] = "有远视眼风险，建议进一步检查矫正";
                    arrowMap["AxialRatioLeft1"] = "";
                }
                if (left_r1_mm <= 39) {
                    respMap["AxialRatioLeft1"] = "扁平角膜，有大散光或圆锥角膜风险，建议进一步检查矫正";
                    arrowMap["AxialRatioLeft1"] = "";
                }
            }
        }

        // 处理左眼屈光数据2
        if (resultMap["AxialRatioLeft2"]) {
            const parts = resultMap["AxialRatioLeft2"].split("D");
            const subParts = parts[0].split("/");
            resultMap["AxialRatioLeft2"] = subParts[1];
            const left_r2_mm = parseFloat(resultMap["AxialRatioLeft2"]);
            if (!isNaN(left_r2_mm)) {
                if (left_r2_mm >= 41 && left_r2_mm <= 43) {
                    respMap["AxialRatioLeft2"] = "陡峭屈光正常";
                }
                if (left_r2_mm > 43) {
                    respMap["AxialRatioLeft2"] = "陡峭屈光较大，有曲率性近视风险";
                    arrowMap["AxialRatioLeft2"] = "";
                }
                if (39 < left_r2_mm && left_r2_mm < 41) {
                    respMap["AxialRatioLeft2"] = "有远视眼风险，建议进一步检查矫正";
                    arrowMap["AxialRatioLeft2"] = "";
                }
                if (left_r2_mm <= 39) {
                    respMap["AxialRatioLeft2"] = "扁平角膜，有大散光或圆锥角膜风险，建议进一步检查矫正";
                    arrowMap["AxialRatioLeft2"] = "";
                }
            }
        }

        // 处理右眼屈光数据1
        if (resultMap["AxialRatioRight1"]) {
            const parts = resultMap["AxialRatioRight1"].split("D");
            const subParts = parts[0].split("/");
            resultMap["AxialRatioRight1"] = subParts[1];
            const right_r1_mm = parseFloat(resultMap["AxialRatioRight1"]);

            if (!isNaN(right_r1_mm)) {
                if (right_r1_mm >= 41 && right_r1_mm <= 43) {
                    respMap["AxialRatioRight1"] = "平坦屈光正常";
                }
                if (right_r1_mm > 43) {
                    respMap["AxialRatioRight1"] = "平坦屈光较大，有曲率性近视风险";
                    arrowMap["AxialRatioRight1"] = "";
                }
                if (right_r1_mm > 39 && right_r1_mm < 41) {
                    respMap["AxialRatioRight1"] = "有远视眼风险，建议进一步检查矫正";
                    arrowMap["AxialRatioRight1"] = "";
                }
                if (right_r1_mm <= 39) {
                    respMap["AxialRatioRight1"] = "扁平角膜，有大散光或圆锥角膜风险，建议进一步检查矫正";
                    arrowMap["AxialRatioRight1"] = "";
                }
            }
        }

        // 处理右眼屈光数据2
        if (resultMap["AxialRatioRight2"]) {
            const parts = resultMap["AxialRatioRight2"].split("D");
            const subParts = parts[0].split("/");
            resultMap["AxialRatioRight2"] = subParts[1];
            const right_r2_mm = parseFloat(resultMap["AxialRatioRight2"]);
            if (!isNaN(right_r2_mm)) {
                if (right_r2_mm >= 41 && right_r2_mm <= 43) {
                    respMap["AxialRatioRight2"] = "陡峭屈光正常";
                }
                if (right_r2_mm > 43) {
                    respMap["AxialRatioRight2"] = "陡峭屈光较大，有曲率性近视风险";
                    arrowMap["AxialRatioRight2"] = "";
                }
                if (39 < right_r2_mm && right_r2_mm < 41) {
                    respMap["AxialRatioRight2"] = "有远视眼风险，建议进一步检查矫正";
                    arrowMap["AxialRatioRight2"] = "";
                }
                if (right_r2_mm <= 39) {
                    respMap["AxialRatioRight2"] = "扁平角膜，有大散光或圆锥角膜风险，建议进一步检查矫正";
                    arrowMap["AxialRatioRight2"] = "";
                }
            }
        }

        // 处理左眼散光数据
        if (resultMap["left_c_avg"]) {
            const parts = resultMap["left_c_avg"].split("D");
            resultMap["left_c_avg"] = parts[0];
            const left_c_avg = parseFloat(resultMap["left_c_avg"]);
            if (!isNaN(left_c_avg)) {
                if (left_c_avg >= -0.5) {
                    respMap["left_c_avg"] = "角膜散光正常";
                }
                if (left_c_avg < -0.5 && left_c_avg >= -1) {
                    respMap["left_c_avg"] = "轻度角膜散光";
                    arrowMap["left_c_avg"] = "";
                }
                if (left_c_avg < -1 && left_c_avg >= -2) {
                    respMap["left_c_avg"] = "中度角膜散光";
                    arrowMap["left_c_avg"] = "";
                }
                if (left_c_avg < -2) {
                    respMap["left_c_avg"] = "重度角膜散光";
                    arrowMap["left_c_avg"] = "";
                }
            }
        }

        // 处理右眼散光数据
        if (resultMap["right_c_avg"]) {
            const parts = resultMap["right_c_avg"].split("D");
            resultMap["right_c_avg"] = parts[0];
            const right_c_avg = parseFloat(resultMap["right_c_avg"]);
            if (!isNaN(right_c_avg)) {
                if (right_c_avg >= -0.5) {
                    respMap["right_c_avg"] = "角膜散光正常";
                }
                if (right_c_avg < -0.5 && right_c_avg >= -1) {
                    respMap["right_c_avg"] = "轻度角膜散光";
                    arrowMap["right_c_avg"] = "";
                }
                if (right_c_avg < -1 && right_c_avg >= -2) {
                    respMap["right_c_avg"] = "中度角膜散光";
                    arrowMap["right_c_avg"] = "";
                }
                if (right_c_avg < -2) {
                    respMap["right_c_avg"] = "重度角膜散光";
                    arrowMap["right_c_avg"] = "";
                }
            }
        }

        // 处理左眼角膜厚度
        if (resultMap["leftCct"]) {
            const leftCct = parseFloat(resultMap["leftCct"]);
            if (!isNaN(leftCct)) {
                if (leftCct >= 0.5 && leftCct <= 0.6) {
                    respMap["leftCct"] = "中央角膜厚度正常";
                }
                if (leftCct < 0.5) {
                    respMap["leftCct"] = "可能屈光不足，有远视或散光风险";
                    arrowMap["leftCct"] = "";
                }
                if (leftCct > 0.6) {
                    respMap["leftCct"] = "有近视、青光眼等风险，建议进一步检查";
                    arrowMap["leftCct"] = "";
                }
            }
        }

        // 处理右眼角膜厚度
        if (resultMap["rightCct"]) {
            const rightCct = parseFloat(resultMap["rightCct"]);
            if (!isNaN(rightCct)) {
                if (rightCct >= 0.5 && rightCct <= 0.6) {
                    respMap["rightCct"] = "中央角膜厚度正常";
                }
                if (rightCct < 0.5) {
                    respMap["rightCct"] = "可能屈光不足，有远视或散光风险";
                    arrowMap["rightCct"] = "";
                }
                if (rightCct > 0.6) {
                    respMap["rightCct"] = "有近视、青光眼等风险，建议进一步检查";
                    arrowMap["rightCct"] = "";
                }
            }
        }

        // 处理左眼前房深度
        if (resultMap["leftAd"]) {
            const leftAd = parseFloat(resultMap["leftAd"]);
            if (!isNaN(leftAd)) {
                if (leftAd >= 2.5 && leftAd <= 3.5) {
                    respMap["leftAd"] = "前房深度正常";
                }
                if (leftAd < 2.5) {
                    respMap["leftAd"] = "浅前房，有远视风险\n建议定期检查眼压及眼底，主动控制眼压，对预防青光眼有积极作用。";
                    arrowMap["leftAd"] = "";
                }
                if (leftAd > 3.5) {
                    respMap["leftAd"] = "有近视风险";
                    arrowMap["leftAd"] = "";
                }
            }
        }

        // 处理右眼前房深度
        if (resultMap["rightAd"]) {
            const rightAd = parseFloat(resultMap["rightAd"]);
            if (!isNaN(rightAd)) {
                if (rightAd >= 2.5 && rightAd <= 3.5) {
                    respMap["rightAd"] = "前房深度正常";
                }
                if (rightAd < 2.5) {
                    respMap["rightAd"] = "浅前房，有远视风险\n2.建议定期检查眼压及眼底，主动控制眼压，对预防青光眼有积极作用。";
                    arrowMap["rightAd"] = "";
                }
                if (rightAd > 3.5) {
                    respMap["rightAd"] = "有近视风险";
                    arrowMap["rightAd"] = "";
                }
            }
        }

        // 处理左眼晶体厚度
        if (resultMap["leftLt"]) {
            const leftLt = parseFloat(resultMap["leftLt"]);
            if (!isNaN(leftLt)) {
                if (leftLt >= 3.5 && leftLt <= 4) {
                    respMap["leftLt"] = "晶体厚度正常";
                }
                if (leftLt < 3.5) {
                    respMap["leftLt"] = "晶体厚度偏低";
                    arrowMap["leftLt"] = "";
                }
                if (leftLt > 4) {
                    respMap["leftLt"] = "晶体厚度偏厚，可能存在调节紧张，有假性近视风险";
                    arrowMap["leftLt"] = "";
                }
            }
        }

        // 处理右眼晶体厚度
        if (resultMap["rightLt"]) {
            const rightLt = parseFloat(resultMap["rightLt"]);
            if (!isNaN(rightLt)) {
                if (rightLt >= 3.5 && rightLt <= 4) {
                    respMap["rightLt"] = "晶体厚度正常";
                }
                if (rightLt < 3.5) {
                    respMap["rightLt"] = "晶体厚度偏低";
                    arrowMap["rightLt"] = "";
                }
                if (rightLt > 4.0) {
                    respMap["rightLt"] = "晶体厚度偏厚，可能存在调节紧张，有假性近视风险";
                    arrowMap["rightLt"] = "";
                }
            }
        }

        // 处理左眼眼轴长度
        if (resultMap["AlLeft"]) {
            const leftAl = parseFloat(resultMap["AlLeft"]);
            if (!isNaN(leftAl)) {
                const standard = this.AlJudge(sex, age);
                if (leftAl > standard) {
                    respMap["AlLeft"] = "眼轴过长，有轴性近视风险，建议定期检查眼轴长度；\n" +
                        "建议进一步检查眼底，评估视网膜脱落和近视性黄斑变性等疾病风险";
                    arrowMap["AlLeft"] = "";
                }
                if (leftAl < standard || leftAl === standard) {
                    respMap["AlLeft"] = "";
                    // respMap["AlLeft"] = "正常";
                }
            }
        }

        // 处理右眼眼轴长度
        if (resultMap["AlRight"]) {
            const rightAl = parseFloat(resultMap["AlRight"]);
            if (!isNaN(rightAl)) {
                const standard = this.AlJudge(sex, age);
                if (rightAl > standard) {
                    respMap["AlRight"] = "眼轴过长，有轴性近视风险，建议定期检查眼轴长度；\n" +
                        "建议进一步检查眼底，评估视网膜脱落和近视性黄斑变性等疾病风险";
                    arrowMap["AlRight"] = "";
                }
                if (rightAl < standard || rightAl === standard) {
                    respMap["AlRight"] = "";
                    // respMap["AlRight"] = "正常";
                }
            }
        }

        // 处理左眼轴率比
        if (resultMap["AxialRatioLeft"] !== "    ") {
            const leftAlCr = parseFloat(resultMap["AxialRatioLeft"]);
            if (!isNaN(leftAlCr)) {
                const standard = this.AlCJudge(age);
                if (leftAlCr > standard) {
                    respMap["AxialRatioLeft"] = "有真性近视风险，建议增加户外活动，注意用眼习惯";
                    arrowMap["AxialRatioLeft"] = "";
                }
                if (leftAlCr < standard || leftAlCr === standard) {
                    respMap["AxialRatioLeft"] = "";
                    // respMap["AxialRatioLeft"] = "正常";
                }
            }
        }

        // 处理右眼轴率比
        if (resultMap["AxialRatioRight"] !== "    ") {
            const rightAlCr = parseFloat(resultMap["AxialRatioRight"]);
            if (!isNaN(rightAlCr)) {
                const standard = this.AlCJudge(age);
                if (rightAlCr > standard) {
                    respMap["AxialRatioRight"] = "有真性近视风险，建议增加户外活动，注意用眼习惯";
                    arrowMap["AxialRatioRight"] = "";
                }
                if (rightAlCr < standard || rightAlCr === standard) {
                    respMap["AxialRatioRight"] = "";
                    // respMap["AxialRatioRight"] = "正常";
                }
            }
        }

        // console.log([respMap, arrowMap])
        let arr = [respMap, arrowMap]
        arr = arr.filter(item => {
            return Object.keys(item).length > 0;
        });
        return arr;
    },


    /**
     * 判断眼轴长度标准值
     * @param {number} sex - 性别
     * @param {number} age - 年龄
     * @returns {number} 标准值
     */
    AlJudge(sex, age) {
        if (sex === 1) {
            switch (age) {
                case 3: return 22.99;
                case 4: return 23.25;
                case 5: return 23.51;
                case 6: return 23.74;
                case 7: return 23.95;
                case 8: return 24.15;
                case 9: return 24.33;
                case 10: return 24.50;
                case 11: return 24.63;
                case 12: return 24.74;
                case 13: return 24.83;
                case 14: return 24.92;
                case 15: return 24.97;
                case 16: return 25;
                case 17: return 25.01;
                case 18: return 24.98;
                default: return 25;
            }
        } else if (sex === 2) {
            switch (age) {
                case 3: return 22.68;
                case 4: return 22.93;
                case 5: return 23.12;
                case 6: return 23.3;
                case 7: return 23.5;
                case 8: return 23.63;
                case 9: return 23.82;
                case 10: return 23.93;
                case 11: return 24.06;
                case 12: return 24.14;
                case 13: return 24.26;
                case 14: return 24.33;
                case 15: return 24.4;
                case 16: return 24.46;
                case 17: return 24.48;
                case 18: return 24.5;
                default: return 25;
            }
        }
        return 0;
    },

    /**
     * 判断另一个眼轴相关指标的标准值
     * @param {number} age - 年龄
     * @returns {number} 标准值
     */
    AlCJudge(age) {
        switch (age) {
            case 3: return 3;
            case 4: return 2.88;
            case 5: return 2.96;
            case 6: return 2.93;
            case 7: return 2.96;
            case 8: return 2.98;
            case 9: return 2.99;
            case 10: return 3.05;
            case 11: return 3.04;
            case 12: return 3.06;
            case 13: return 3.06;
            case 14: return 3.07;
            case 15: return 3.06;
            case 16: return 3.08;
            case 17: return 3.11;
            case 18: return 3.1;
            default: return 3;
        }
    }
};



